"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._getStringViaHTTP = void 0;
let http = require('http');
async function _getStringViaHTTP(theUrl) {
    return new Promise(function (resolve) {
        let r = {
            success: false,
            message: "未捕获到错误",
            content: ""
        };
        http.get(theUrl, (res) => {
            const { statusCode } = res;
            let error;
            if (statusCode !== 200) {
                error = new Error(`请求失败. Status Code: ${statusCode}`);
            }
            if (error) {
                console.error(error.message);
                res.resume();
                r.message = error.message;
                resolve(r);
                return;
            }
            res.setEncoding('utf8');
            let rawData = '';
            res.on('data', (chunk) => {
                rawData += chunk;
            });
            res.on('end', () => {
                r.success = true;
                r.content = rawData;
                resolve(r);
            });
        }).on('error', (e) => {
            r.message = e.message;
            resolve(r);
        });
    });
}
exports._getStringViaHTTP = _getStringViaHTTP;
